<!--# layout("/common/layout.html",{"jsBase":"/js/live/courseLive/"}){ -->

<form class="layui-form layui-form-pane" id="addForm"  enctype="multipart/form-data" lay-filter="editform">
    <input type="hidden" name="liveId" id="liveId">
    <input type="hidden" name="brief" id="brief">
    <input type="hidden" name="tearchName" id="tearchName">
    <br>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">直播主题</label>
				<div class="layui-input-inline">
                    <input type="text" name="liveTitle" id="liveTitle" autocomplete="off" maxlength="50" class="layui-input" lay-verify="required">
				</div>
            </div>
            <div class="layui-inline">
            <label class="layui-form-label">副标题</label>
				<div class="layui-input-inline">
                    <input type="text" name="liveSubTitle" id="liveSubTitle" autocomplete="off" maxlength="50" class="layui-input" lay-verify="required">
				</div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <layui:image id="cover" tagName="封面" tips=""/>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <!--#if(accessType==6){ -->
            <div class="layui-inline">
            <label class="layui-form-label">归属省份</label>
				<div class="layui-input-inline">
                        <layui:simpleDataSelect name="provinceId" value="${has(courseLive)?courseLive.provinceId:''}" data="${provinceList}"
                                    attrId="provId" attrName="provName" laySearch="true"  layFilter="colFilter"/>
				</div>
            </div>
            <!--#} -->


            <div class="layui-inline">
                <label class="layui-form-label">课程老师</label>
                <div class="layui-input-inline">
                    <select style="width:40%" class="select" name="teacherId" id="teacherId" selectValue="" promtion="请选择" lay-search lay-filter="teacher" lay-verify="required">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label">直播类型</label>
                <layui:simpleDictSelect style='layui-input-inline' type="LIVE_TYPE" layVerify="required"
                                        id="liveType" name="liveType" value="" />
            </div>


            <div class="layui-inline">
                <label class="layui-form-label">所属平台</label>
                <div class="layui-input-inline">
                    <select style="width:40%"  name="platform" id="platform" selectValue="${courseLive.platform}">
                        <option value="1">圣达信</option>
                        <option value="2">高三网</option>
                        <option value="3">七天网络</option>
                    </select>
                </div>
            </div>

        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">优惠名额</label>
                <div class="layui-input-inline">
                    <input type="text" name="freeNum" id="freeNum" autocomplete="off" maxlength="50" class="layui-input" lay-verify="required">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label" style="width: 120px">直播价格(分)</label>
                <div class="layui-input-inline" style="width: 220px">
                    <input type="text" name="coursePrice" id="coursePrice" autocomplete="off" maxlength="50" class="layui-input" lay-verify="number">
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">直播状态</label>
                <div class="layui-input-inline">
                    <select style="width:40%"  name="liveStatus" id="liveStatus" selectValue="${courseLive.liveStatus}">
                        <option value="1" >预约</option>
                        <option value="2">直播中</option>
                        <option value="3">回看</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">在线状态</label>
                <div class="layui-input-inline">
                    <select style="width:40%"  name="courseStatus" id="courseStatus" selectValue="${courseLive.courseStatus}" >
                        <option value="1" >上线</option>
                        <option value="0">下线</option>
                    </select>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">开始时间</label>
				<div class="layui-input-inline">
                    <input type="text" name="startTime"  id="startTime" autocomplete="off" class="layui-input input-datetime" lay-verify="required|datetime">
				</div>
            </div>
            <div class="layui-inline">
            <label class="layui-form-label">结束时间</label>
				<div class="layui-input-inline">
                     <input type="text" name="endTime"  id="endTime" autocomplete="off" class="layui-input input-datetime" lay-verify="required|datetime">
				</div>
            </div>

        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">

        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label">拉流地址</label>
                <div class="layui-input-inline">
                    <input type="text" name="pullUrl" id="pullUrl" autocomplete="off" class="layui-input" lay-verify="required" style="width: 400px">
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <layui:singleFile id="coursewareUrl" tagName="课件" tips=""/>
        </div>
    </div>


    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">直播内容</label>
                <div class="layui-input-block" style="width:712px;z-index: 999" id="">
                    <script id="content" type="text/plain" placeholder="请输入" ></script>
                </div>
            </div>

        </div>
    </div>
    <layui:submitButtons id="addButton" />
</form>
<!--#} -->
<script type="text/javascript"  src="${ctxPath}/plugins/ueditor/ueditor.config.js"></script>
<script type="text/javascript"  src="${ctxPath}/plugins/ueditor/ueditor.all.js"></script>
<script>
    Common.initImage();

    var ue = UE.getEditor('content',{
        toolbars: [["undo", "redo",
            "|", "fontsize", "forecolor", "bold", "italic", "underline",
            "|", "justifyleft", "justifycenter", "justifyright", "justifyjustify", "lineheight",
            "|", "directionalityltr", "directionalityrtl", "indent",
            "|", "backcolor", "autotypeset", "spechars", "source",
            "|", "searchreplace", "|", "fullscreen","mobile"]],
        serverUrl: "${ctxPath}/content/ebookChapter/config",
        autoHeightEnabled: false,
        elementPathEnabled : false,　　//是否启用元素路径，默认是true显示
        wordCount:false,          //是否开启字数统计
        initialFrameHeight:300
    });

layui.extend({
    loading: '../../../plugins/layui_extends/loading/loading',
    selectN: '../../../plugins/layui_extends/selectN'
}).define([ 'form', 'laydate', 'table','loading','courseLiveApi','selectN'], function(exports) {
    var form = layui.form;
    var laydate = layui.laydate;
    var courseLiveApi = layui.courseLiveApi;
    var index = layui.index;
    var isNew = true;
    var selectN = layui.selectN;
    var colN;
    <!--# if(!(isEmpty(courseLiveJson))){  -->
        isNew = false;
    <!--# } -->

    laydate.render({
        elem: '#startTime' //指定元素
        ,type: 'datetime'
        ,value: new Date()
    });

    laydate.render({
        elem: '#endTime' //指定元素
        ,type: 'datetime'
        ,value: new Date()
    });

    var view = {
        initCol:function(provinceId){
            $("#teacher").empty();
             colN = selectN({
                //元素容器【必填】
                elem: '#teacher'

                //候选数据【必填】
                ,data: "getTeacher.json"

                //默认值
                ,selected: ['${courseLive.teacherId!}']
                //input的name 不设置与选择器相同(去#.)
                ,name: 'teacherId'
                //候选项数据的键名
                ,field: {idName:'customerId',titleName:'customerName'}
        });
        },
        init:function(){
            Lib.initGenrealForm($("#addForm"),form);
            this.initSubmit();
        },
        initSubmit:function(){
            $("#addButton").click(function(){
                // $("#addButton").hide();
                // $("#addButton-loading").show();
                // $("#addButton-loading").loading();
                form.on('submit(form)', function(){
                    if($('#teacherId option:selected').val()==null){
                        Common.info("请选择老师！");
                        return;
                    }

                    var startTime=$("#startTime").val();
                    var start=new Date(startTime.replace("-", "/").replace("-", "/"));
                    var endTime=$("#endTime").val();
                    var end=new Date(endTime.replace("-", "/").replace("-", "/"));

                    if(end<=start){
                        Common.info("结束时间必须大于开始时间");
                        return ;
                    }

                    $("#brief").val(ue.getContent())
                    courseLiveApi.saveForm(isNew,$('#addForm'),function(){
                        parent.window.dataReload();
                        Common.info("保存成功");
                        Lib.closeFrame();
                    });
                });
            });

            $("#addButton-cancel").click(function(){
                Lib.closeFrame();
            });
        }

    }
    view.init();
    form.on('select(colFilter)', function(data){
        getTeacher(data.value);
    });
    form.on('select(teacher)', function(data){
        $("#teacherName").val($('#teacherId option:selected').text());
        getLecture();
    });

    function getTeacher(provinceId) {
        $.ajax({
            type: 'POST',
            url: "${ctxPath}/live/courseLive/getTeacher.json",
            data: {

            },
            dataType:'json',
            success: function(data){
                $("#teacherId").html("");
                $.each(data, function(key, val) {
                    var option1 = $("<option>").val(val.customerId).text(val.customerName);
                    var teacherId = "${courseLive.teacherId}";
                    if(!isNew && val.customerId ==teacherId ){
                        option1 = $("<option selected>").val(val.customerId).text(val.customerName);
                    }
                    $("#teacherId").append(option1);
                });
                form.render('select');
                getLecture();
            }
        });
    }

    function getLecture() {
        var teacherId = $('#teacherId option:selected').val();
        $.ajax({
            type: 'POST',
            url: "${ctxPath}/live/courseLive/getLecture.json",
            data: {
                teacherId:teacherId
            },
            dataType:'json',
            success: function(data){
                $("#lectureId").html("");
                $.each(data, function(key, val) {
                    var option1 = $("<option>").val(val.lectureId).text(val.lectureTitle);
                    var lectureId = "${courseLive.lectureId}";
                    if(!isNew && val.lectureId ==lectureId ){
                        option1 = $("<option selected>").val(val.lectureId).text(val.lectureTitle);
                    }
                    $("#lectureId").append(option1);
                });
                form.render('select');

            }
        });
    }
    getTeacher();

    <!--# if(!(isEmpty(courseLiveJson))){  -->
    $("#teacherId").val("${courseLive.teacherId}");
    $('#teacherId option[value="${courseLive.teacherId}"]').attr("selected","selected");
    var formJson = ${courseLiveJson};
    form.val("editform",formJson);
    $(".image-preview").each(function() {
        $(this).attr("src",formJson[$(this).attr("id")]);
    });
    <!--# } -->
    ue.setContent($("#brief").val());
});
</script>
